<template>
<div class="layerRtb layerRtb-threecolumn layerRtb-right">
    <three-title :title="{name:'整改'}" :close="false">
        <span tag="i" class="rig_close fr" @click="$parent.$parent.clickFourShow()"></span>
    </three-title>
    <div class="layerRtb-scroll thinScroll" v-scrollHeight = "137">
        <div class="analyItem">
            <p class="analyItemTit tx-center">整改内容</p>
            <div class="analyItemCon">
                <p class="col-md-4">
                    <span class="cLightGray pr8 fl">罚款金额</span>
                    <span>{{changeContent !== null ? changeContent.money : ''}}</span>
                </p>
                <p class="col-md-4">
                    <span class="cLightGray pr8 fl">结束时间</span>
                    <span>{{changeContent !== null ?  $utils.format('yyyy-MM-dd', changeContent.endTime) : ''}}</span>
                </p>
                <!-- <p class="col-md-4">
                    <span class="cLightGray pr8 fl">积分</span>
                    <span>{{changeContent !== null ?  changeContent.integral : ''}}</span>
                </p> -->
                 <p class="col-md-12">
                    <span class="cLightGray pr8 fl">整改描述</span>
                    <span>{{changeContent !== null ? changeContent.content : ''}}</span>
                </p>
                <p class="col-md-12" v-if='changeContent !== null' >
                    <span class="cLightGray pr8 fl">整改图片</span>
                    <rx-viewer :images="changeContent.rectifyOrderPhotoList" class="fl">
                        <div class="clearfix">
                            <div v-for="(itemImg, index) of changeContent.rectifyOrderPhotoList" :key="index" class="fl mr10">
                                <img :src="itemImg | smallImg(78, 78)" :alt="index">
                            </div>
                        </div>
                    </rx-viewer>
                </p>
            </div>
        </div>
        <div class="analyItem">
            <p class="analyItemTit tx-center">整改</p>
            <div class="analyItemCon">
                <p class="col-md-12 mt10">
                    <span class="cLightGray pr8 fl">整改描述</span>
                    <span v-if="projectChangeList.length > 0 && currentContent.isRework === 0">{{changeTextDec}}</span>
                    <textarea v-else v-model="changeTextDec" placeholder="请输入整改描述" class="col-md-10"></textarea>
                </p>
                <p class="col-md-12 mt10">
                    <span class="cLightGray pr8 fl">图片上传</span>
                    <rx-upload
                        v-if="buttonIsShow"
                        class="fl"
                        :data="{id: 11}" :init="{class: 7, mime: 1}"
                        :elStyle="{width:'90px', height: '80px'}"
                        @success="successUpload">
                        <div class="fl uiImgUpload uiImgUpload-gblock mr10">
                            <a href="javascript:">
                                <span type="file" value="" class="file"></span>
                                <em class="bgIcon file-ico"></em>
                            </a>
                        </div>
                    </rx-upload>
                    <rx-viewer :images="changeList" class="fl">
                        <div class="clearfix">
                            <div v-for="(item, index) of changeList" :key="index" class="fl mr10 relative imgBox imgOper">
                                <img :src="item | smallImg(78, 78)" :alt="index">
                                <div v-if="buttonIsShow && currentContent !== null &&  currentContent.isRework === 1" class="operBox">
                                    <div class="flex">
                                        <el-button type="primary" icon="el-icon-zoom-in" circle class="enlarge_viewer"></el-button>
                                        <el-button type="primary" icon="el-icon-delete" circle  @click="deleteImg(index)"></el-button>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </rx-viewer>
                </p>
            </div>
        </div>
        <div class="analyItem" v-if="projectChangeList.length > 0 &&  currentContent !== null && currentContent.isRework === 1">
            <p class="analyItemTit tx-center">打回内容</p>
            <div class="analyItemCon">
                <p class="col-md-6">
                    <span class="cLightGray pr8 fl">打回时间</span>
                    <span>{{currentContent !== null ?  $utils.format('yyyy-MM-dd', currentContent.reworkTime) : ''}}</span>
                </p>
                <p class="col-md-6">
                    <span class="cLightGray pr8 fl">结束时间</span>
                    <span>{{currentContent !== null ?  $utils.format('yyyy-MM-dd', currentContent.reworkEndTime) : ''}}</span>
                </p>
                <p class="col-md-12">
                    <span class="cLightGray pr8 fl">打回理由</span>
                    <span>{{currentContent !== null ? currentContent.reworkReason : ''}}</span>
                </p>
                <p class="col-md-12" v-if='currentContent !== null' >
                    <span class="cLightGray pr8 fl">图片查看</span>
                    <rx-viewer :images="currentContent.reWorkPhotoList" class="fl">
                        <div class="clearfix">
                            <div v-for="(itemImg, index) of currentContent.reWorkPhotoList" :key="index" class="fl mr10">
                                <img :src="itemImg | smallImg(78, 78)" :alt="index">
                            </div>
                        </div>
                    </rx-viewer>
                </p>
            </div>
        </div>
    </div>
    <div class="layerRtb-footer">
        <div class="analyItem">
            <p class="analyItemTit tx-center">综合</p>
            <div class="analyItemCon">
                <div class="tx-center">
                    <input type="button" class="uiBtn-normal uiBtn-blue" value="确定" @click="saveRectifyOrderRecord" v-if="buttonIsShow">
                </div>
            </div>
        </div>
    </div>
</div>
</template>
<script>
import { mapGetters, mapMutations } from 'vuex'
import { getRectifyOrder, saveRectifyOrderRecord } from '../../../Resources/Api/scene'
export default {
    props: ['type', 'role'],
    data () {
        return {
            changeContent: null, // 整改内容
            changeList: [], // 整改图片
            changeTextDec: '', // 整改描述
            projectChangeList: [], // 整改数组
            currentContent: null, // 当前对象
            buttonIsShow: false // 按钮显示与隐藏
        }
    },
    computed: {
        ...mapGetters(['leftInfo', 'userInfo', 'twoToThreeInfo'])
    },
    created () {
        this.getRectifyOrder()
        this.buttonType()
    },
    methods: {
        ...mapMutations({
            setUpDatePlate: `SET_UPDATE_PLATE`
        }),
        // 路由跳转路径拼接
        routerPath (path) {
            return this.$route.matched[1].path + '/' + path
        },
        // 按钮显示与隐藏
        buttonType () {
            if (this.userInfo.as_diquId === 39) {
                if (this.twoToThreeInfo.status === this.type) {
                    this.buttonIsShow = true
                } else {
                    this.buttonIsShow = false
                }
            } else {
                this.buttonIsShow = false
            }
        },
        // 获取数据
        getRectifyOrder () {
            let parm = {
                orderCode: this.$route.query.code
            }
            // 接口获取数据
            getRectifyOrder(parm).then(results => {
                if (results.data.StatusCode === 1) {
                    this.changeContent = results.data.Body.rectifyOrder
                    this.projectChangeList = results.data.Body.rectifyOrderRecordList
                    if (this.projectChangeList.length > 0) {
                        // 获取项目经理最近的整改内容
                        const currentContent = this.projectChangeList.filter((item) => { return item.delFlag === 0 })
                        this.currentContent = currentContent[0]
                        this.changeList = this.currentContent.recordPhotoList
                        this.changeTextDec = this.currentContent.content
                    }
                }
            }).catch(error => {
                console.log(error)
            })
        },
        // 直接进行路由跳转路径
        routerPush (path) {
            this.$router.push(this.$route.matched[1].path + '/' + path)
        },
        // 图片上传
        successUpload (value) {
            this.changeList.push(value.src)
        },
        // 图片删除
        deleteImg (index) {
            this.changeList.splice(index, 1)
        },
        // 提交罚款
        saveRectifyOrderRecord () {
            if (this.twoToThreeInfo.timeoutFlag) {
                this.$message({
                    type: 'info',
                    message: '抱歉,订单超时,未提交成功'
                })
                return false
            }
            if (this.changeTextDec === '') {
                this.$message('输入整改问题描述')
                return false
            }
            let parmObject = {
                orderNo: this.leftInfo.orderno,
                orderCode: this.$route.query.code,
                content: this.changeTextDec
            }
            let parm = {
                rectifyOrderRecord: parmObject,
                photoList: this.changeList,
                userNo: this.userInfo.as_cardNo,
                userName: this.userInfo.as_fullName
            }
            saveRectifyOrderRecord(parm).then((result) => {
                if (result.data.StatusCode === 1) {
                    this.$message('提交成功')
                    this.buttonIsShow = false
                    this.$parent.$parent.clickFourShow()
                    this.setUpDatePlate()
                } else {
                    this.$message(result.data.statusMsg)
                }
            }).catch((error) => {
                console.log(error)
            })
        }
    }
}
</script>
